JAVA					= java
JAVAC					= javac
JAR						= jar
@bpv(BUILD_RUNNER)@		= nqp-j$(BAT)
@bpv(BUILD_RUNNER_BIN)@	= @nfp($(BASE_DIR)/@bpm(BUILD_RUNNER)@)@
@bpv(NQP)@				= nqp$(BAT)

@bsv(NQP_LIB_DIR)@ = @nfp($(NQP_HOME)/runtime)@

@bpv(RUNNER_JAR_DIR)@ = @nfp(@bpm(BUILD_DIR)@/share/runtime)@
@bpv(RUNNER_LIB_DIR)@ = @nfp(@bpm(BUILD_DIR)@/share/lib)@

ASM = @asm@
ASMTREE = @asmtree@
JLINE = @jline@
JNA = @jna@

RUNTIME_JAVAS = \
  @nfp(src/vm/jvm/runtime/org/perl6/nqp/io/*.java)@ \
  @nfp(src/vm/jvm/runtime/org/perl6/nqp/jast2bc/*.java)@ \
  @nfp(src/vm/jvm/runtime/org/perl6/nqp/runtime/*.java)@ \
  @nfp(src/vm/jvm/runtime/org/perl6/nqp/sixmodel/*.java)@ \
  @nfp(src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/*.java)@ \
  @nfp(src/vm/jvm/runtime/org/perl6/nqp/tools/*.java)@ \

@bsv(RUNTIME)@ = @nfp(@bpm(RUNNER_JAR_DIR)@/nqp-runtime.@bext@)@
THIRDPARTY_JARS = $(ASM)@cpsep@$(ASMTREE)@cpsep@$(JLINE)@cpsep@$(JNA)
@bpv(RUNNER_JARS)@ = @nfplq($(ASM) $(ASMTREE) $(JLINE) $(JNA))@
@bpv(RUNNER_LIBS)@ = @nfplq(nqp.@bext@)@
@bpv(EVAL_CLIENT)@ = @nfp(tools/jvm/eval-client.pl)@

@bpv(STAGE0_NQP)@ = $(JAVA) -cp @bpm(STAGE0_DIR)@ -Xbootclasspath/a:@bpm(STAGE0_DIR)@@cpsep@@bsm(RUNTIME)@@cpsep@@q($(THIRDPARTY_JARS))@@cpsep@@nfp(@bpm(STAGE0_DIR)@/nqp.jar)@ nqp --bootstrap
@bpv(STAGE1_NQP)@ = $(JAVA) -cp @bpm(STAGE1_DIR)@ -Xbootclasspath/a:@bpm(STAGE1_DIR)@@cpsep@@bsm(RUNTIME)@@cpsep@@q($(THIRDPARTY_JARS))@@cpsep@@nfp(@bpm(STAGE1_DIR)@/nqp.jar)@ nqp --bootstrap

@for_stages(@bpv(@ucstage@_GEN_CAT)@ = @bpm(GEN_CAT)@ @lcstage@
@bpv(NQP_@ucstage@_FLAGS)@ = --javaclass=nqp
)@

# 
@bpv(ASTNODES_SOURCES)@	= @nfp(src/vm/jvm/QAST/JASTNodes.nqp)@

@bpv(NQP_SOURCES_EXTRA)@ = @nfp(src/vm/@backend@/NQP/Ops.nqp)@

@bpv(CLEANUPS_EXTRA)@ = \
	*.class \
	bin \
	nqp \
	nqp.bat \
	jvmconfig.properties \
	@nfpq(@bpm(BUILD_DIR)@/share)@

@include(Makefile-backend-common)@

@bpm(STAGE0_DIR)@: @bsm(RUNTIME)@

@backend_prefix@-dirs::
	$(NOECHO)$(MKPATH) @q(@bpm(RUNNER_JAR_DIR)@)@ @q(@bpm(RUNNER_LIB_DIR)@)@

@backend_prefix@-install::
	@echo(+++ Installing @uc(@backend@)@ specifics)@
	$(NOECHO)$(CP) @q($(ASM))@ @q($(ASMTREE))@ @q($(DESTDIR@nop())@@bsm(NQP_LIB_DIR)@)@
	$(NOECHO)$(CP) @q($(JLINE))@ @q($(JNA))@ @q($(DESTDIR@nop())@@bsm(NQP_LIB_DIR)@)@
	$(NOECHO)$(CP) @q(@bsm(RUNTIME)@)@ @q($(DESTDIR@nop())@@bsm(NQP_LIB_DIR)@)@
	$(NOECHO)$(CP) @q(@bpm(EVAL_CLIENT)@)@ @q($(DESTDIR)$(BIN_DIR))@
	$(NOECHO)$(CHMOD) 0755 @nfpq($(DESTDIR)$(BIN_DIR)/eval-client.pl)@
	$(NOECHO)$(CONFIGURE) --expand=nqp-j --out=@nfpq($(DESTIR)$(PREFIX)/bin/@bpm(BUILD_RUNNER)@)@ \
				 --set-var=ctx_subdir=@shquot(@backend_subdir@)@ \
				 --set-var=jar_dir=@q($(DESTIR@nop())@@bsm(NQP_LIB_DIR)@)@ \
				 --set-var=lib_dir=@q($(DESTIR)$(NQP_LIB_DIR))@ \
				 --set-var=cur_dir=@q()@
	$(NOECHO)$(CHMOD) 755 @nfpq($(DESTIR)$(PREFIX)/bin/@bpm(BUILD_RUNNER)@)@

@bsm(RUNTIME)@: $(RUNTIME_JAVAS) @mkquot(@script(gen-jvm-properties.pl)@)@
	@echo(+++ Preparing Java runtime)@
	$(NOECHO)$(MKPATH) bin
	$(NOECHO)$(JAVAC) --release 9 -cp @q($(THIRDPARTY_JARS))@ -g -d bin -encoding UTF8 $(RUNTIME_JAVAS)
	$(NOECHO)$(PERL5) @shquot(@script(gen-jvm-properties.pl)@)@ . @nfpq($(NQP_HOME))@ @q($(THIRDPARTY_JARS))@ > jvmconfig.properties
	$(NOECHO)$(PERL5) @shquot(@script(gen-jvm-properties.pl)@)@ @nfpq(@prefix@)@ @nfpq($(NQP_HOME))@ @q($(THIRDPARTY_JARS))@ > @nfpq(bin/jvmconfig.properties)@
	$(NOECHO)$(JAR) cf0 @bsm(RUNTIME)@ -C @nfp(bin/)@ .

@bpm(BUILD_RUNNER)@: @mkquot(@configure_script@)@ @@template(nqp-j)@@ @@template(runner-prelude)@@
	@echo(+++ Setting up	$@)@
	$(NOECHO)$(CP) @bpm(RUNNER_JARS)@ @q(@bpm(RUNNER_JAR_DIR)@)@
	$(NOECHO)$(CP) @bpm(RUNNER_LIBS)@ @q(@bpm(RUNNER_LIB_DIR)@)@
	$(NOECHO)$(CONFIGURE) --expand=nqp-j --out=@nfpq($(BASE_DIR)/@bpm(BUILD_RUNNER)@)@ \
				 --set-var=ctx_subdir=@q(@backend_subdir@)@ \
				 --set-var=jar_dir=@q(@bpm(RUNNER_JAR_DIR)@)@ \
				 --set-var=lib_dir=@q(@bpm(RUNNER_LIB_DIR)@)@ \
				 --set-var=cur_dir=@q(.:)@
	$(NOECHO)$(CHMOD) 755 @q(@bpm(BUILD_RUNNER)@)@

@backend_prefix@-runner-default: @backend_prefix@-all
	@echo(+++ Setting up default runner)@
	$(NOECHO)$(CP) @q(@bpm(BUILD_RUNNER)@)@ @bpm(NQP)@
	$(NOECHO)$(CHMOD) 755 @bpm(NQP)@

@backend_prefix@-runner-default-install: @backend_prefix@-runner-default @backend_prefix@-install
	@echo(+++ Installing default runner)@
	$(NOECHO)$(CP) @nfpq($(DESTDIR)$(BIN_DIR)/@bpm(BUILD_RUNNER)@)@ @nfpq($(DESTDIR)$(BIN_DIR)/@bpm(NQP)@)@
	$(NOECHO)$(CHMOD) 755 @nfpq($(DESTDIR)$(BIN_DIR)/@bpm(NQP)@)@

# vim: ft=make noexpandtab ts=4 sw=4
